package sebastiankerckhof.scene.geometry;

import sebastiankerckhof.math.Matrix4f;
import sebastiankerckhof.math.Vector3f;
import sebastiankerckhof.render.raytrace.Ray;
import sebastiankerckhof.render.raytrace.Hit.Hit;
import sebastiankerckhof.scene.material.Material;
import sebastiankerckhof.scene.texture.Texture;
import sebastiankerckhof.scene.transformation.TransformationStack;

public class Sphere implements Surface{
	private Material material;
	private Texture texture;
	private TransformationStack motion;
	
	private final Vector3f center;
  private final float radius;
	public Sphere(Vector3f center, float radius){
		this.center = center;
    this.radius = radius;
	}
	
  Vector3D intersection = ray.getOrigin().add(ray.getDirection().scale(distance));
  Vector3D normal = intersection.sub(this.center).scale(1.0 / this.radius);
  
	@Override
	public Material getMaterial() {
		return this.material;
	}

	@Override
	public Texture getTexture() {
		return this.texture;
	}
	
	@Override
	public void setMaterial(Material material) {
		this.material = material;
	}

	@Override
	public void setTexture(Texture texture) {
		this.texture = texture;
	}

	@Override
  public void transform(Matrix4f M, Matrix4f N) {
	  this.triangles.transform(M, N);
  }

	@Override
  public boolean hit(Ray r, float t0, Hit h) {
	  return this.triangles.hit(r, t0, h);
  }

	BBox bbox;
	@Override
  public BBox getBBox() {
	  return this.triangles.getBBox();
  }

	@Override
  public float getMidPoint(int axis) {
	  return this.triangles.getMidPoint(axis);
  }

	@Override
  public void setMotion(TransformationStack t) {
	  this.motion = t;
  }

	@Override
  public void transformToStep(float step) {
		if(step != 1.0f && motion != null && motion.size() > 0){
			this.transform(motion.peekStep(step),motion.peekNormalStep(step));
		}
	  
  }

	@Override
  public void transformFromStep(float step) {
		if(step != 1.0f && motion != null && motion.size() > 0){
			this.transform(motion.peekNormalStep(step).transpose(),motion.peekStep(step).transpose());
		}
  }

	@Override
  public boolean hit(Ray r, float t0, Hit h, float time) {
	  // TODO Auto-generated method stub
	  return false;
  }
}
